package graphics.objects;
import org.lwjgl.opengl.GL11;

import tools.Floatmath;
import tools.Help;
import tools.Point;
import game.engine.GSync;
import graphics.system.Color;
import graphics.system.GLTools;
public class GCircle extends GShape {
	private float radius;
	public GCircle(Point pos, float radius, float angle, Color color) {
		super(pos, angle, color);
		this.radius = radius;
		node.setBoundingRad(radius);
		this.glowscale = 3;
	}
	@Override
	public void draw() {
		GL11.glPushMatrix();
		node.setUpGl();
		GLTools.drawCircle(Point.ZERO, radius, 0, color, false);
		GL11.glPopMatrix();
	}
	@Override
	public void drawShadow(Point lightPos, float lradius) {
		if (!this.hasShadow)
			return;
		GL11.glPushMatrix();
		node.setUpGl();
		GLTools.drawCircle(Point.ZERO, this.radius, 0, Color.black, false);
		float la = node.pos.sub(lightPos).angle() + Floatmath.PIHALF;
		Point s = new Point(radius * Floatmath.cos(la), radius * Floatmath.sin(la));
		Point e = new Point(radius * Floatmath.cos(la), radius * Floatmath.sin(la)).mul(-1);
		Point b = s.add(s.add(node.pos).sub(lightPos).mul(1000));
		Point d = e.add(e.add(node.pos).sub(lightPos).mul(1000));
		GL11.glRotatef(Floatmath.radToDeg(node.apos), 0, 0, -1);
		Color.black.set();
		GL11.glBegin(GL11.GL_QUADS);
		GL11.glVertex2f(s.x, s.y);
		GL11.glVertex2f(e.x, e.y);
		GL11.glVertex2f(d.x, d.y);
		GL11.glVertex2f(b.x, b.y);
		GL11.glEnd();
		GL11.glPopMatrix();
	}
	@Override
	public void drawGlow() {
		GL11.glPushMatrix();
		node.setUpGl();
		if (this.hasGlow())
			GLTools.drawCircle(Point.ZERO, radius, 0, glowColor, false);
		GL11.glPopMatrix();
	}
	public void drawDebug() {
		GL11.glPushMatrix();
		node.setUpGl();
		GLTools.drawCircleLine(Point.ZERO, radius, 0, Color.blue, false);
		GL11.glPopMatrix();
	}
	@Override
	public void delete() {
	}
	@Override
	public String toFileString() {
		String s = super.toFileString();
		s = s + "/" + radius;
		return s;
	}
	@Override
	public int fromFileString(String s) {
		int off = super.fromFileString(s);
		String l[] = s.split("/");
		this.radius = Float.valueOf(l[off + 1]);
		node.boundingrad = radius;
		return off + 1;
	}
}
